package com.huluobo.a2207douyindemo.mvpdemo;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.huluobo.a2207douyindemo.R;

public class LoginDemoActivity extends AppCompatActivity implements LoginDemoView {

    LoginDemoPresenter presenter = new LoginDemoPresenter(this);

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login_demo);

        EditText username = findViewById(R.id.loginDemo_username);
        EditText password = findViewById(R.id.loginDemo_password);
        Button button = findViewById(R.id.loginDemo_btn);

        button.setOnClickListener(v -> {
            presenter.login(username.getText().toString(), password.getText().toString());
        });
    }

    @Override
    public void onSuccess(UserBean userBean) {
        Toast.makeText(this, "登录成功:" + userBean.getUsername(), Toast.LENGTH_SHORT).show();
    }

    @Override
    public void onFailed(String error) {
        Toast.makeText(this, "登录失败:" + error, Toast.LENGTH_SHORT).show();
    }
}